import Vue from 'vue'
import Router from 'vue-router'
import NProgress from 'nprogress' // 页面的加载状态
import 'nprogress/nprogress.css' // 样式
// const path = "/webrtc-vue/web"

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
NProgress.configure({
    showSpinner: false
}) // NProgress Configuration
// console.log(process.env.BASE_URL)

//路由懒加载
const Nav = () => import('@/views/Nav')
const Home = () => import('@/views/Home')
const Article = () => import('@/views/Article')
const Add = () => import('@/views/Add')
const Person = () => import('@/views/Person')
const Reminder = () => import('@/views/Reminder')
// const home = () => import('@/components/home')
// const details = () => import('@/components/details')
Vue.use(Router);

const routes = [
    // {
    //     path: '/',
    //     redirect: '/home'
    // },
    {
        path: '/',
        component: Nav,
        name: 'Home',
        redirect: '/home',
        children: [
            {
                name: 'home',
                path: 'home',
                component: Home,
            },
            {

                path: 'article/:id',
                component: Article,
            },
            {
                path: '/person',
                redirect: '/person/article',
            },
            {
                path: 'person/:type',
                component: Person,
            },
            {
                path: 'add',
                component: Add,
            },
            {
                path: 'reminder',
                component: Reminder,
            }
        ]
    },

    {
        path: '/replay',
        component: Home
    },

    {
        path: "*",
        redirect: '/',
    }

]

const router = new Router({
    base: process.env.BASE_URL,
    routes,
    // mode: 'history'
})

router.beforeEach((to, from, next) => {
    NProgress.start()
    NProgress.done()
    next()
})

router.afterEach(() => {
    // finish progress bar
    NProgress.done()
})


export default router